package Guis.Tarea;

import java.awt.Color;
import java.awt.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class FormatoTabla extends DefaultTableCellRenderer {

    public FormatoTabla() {
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) {
        setBackground(Color.white);//color de fondo
        table.setForeground(Color.black);//color de texto
        //Si la celda corresponde a una fila con estado FALSE, se cambia el color de fondo a rojo
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        Date d = new GregorianCalendar().getTime();
        try {
            d = sdf.parse((String) table.getValueAt(row, 5));
        } catch (ParseException ex) {
        }
        Date da = new GregorianCalendar().getTime();
        if (!table.getValueAt(row, 4).equals("100.0") && d.before(da)) {
            setBackground(Color.red);
        }

        super.getTableCellRendererComponent(table, value, selected, focused, row, column);
        return this;
    }
}